package cn.go.bus;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import cn.go.buster.ThreadMode;
import cn.go.buster.annotation.GoBus;
import cn.go.buster.launcher.api.GoBuster;

/**
 * @author logcat
 */
public class SecondActivity extends AppCompatActivity {

    private String TAG = this.getClass().getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        GoBuster.getInstance().register(this);
    }

    public void logPrint(View view) {

        GoBuster.getInstance().post("tag1" , "value1");
    }

    public void goToPageThree(View view) {
        startActivity(new Intent(this , ThirdActivity.class));
    }


    @GoBus(tag = "tag3" , threadMode = ThreadMode.MAIN)
    public void printLog(){
        Log.d(TAG, "printLog: ");
        Toast.makeText(this, "tag3的目标方法被调用", Toast.LENGTH_SHORT).show();
    }


    @GoBus(tag = "tag1" , threadMode = ThreadMode.MAIN)
    public void executeTag1(String value){
        Log.d(TAG, "这是在SecondActivity: " + value);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        GoBuster.getInstance().unRegister(this);
    }
}